package com.hean.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.view.View;

import com.hean.activity.R;
import com.hean.entity.Cube;

public class MyView extends View{
	private Cube cube;

	public void setCube(Cube cube) {
		this.cube = cube;
	}
	public MyView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	@Override
	protected void onDraw(Canvas canvas) {
		System.out.println(getHeight()+",myview");
		super.onDraw(canvas);
		Paint paint = new Paint();
		canvas.drawColor(Color.rgb(255, 255, 128));
		//draw image
		BitmapDrawable bitmapDrawable=(BitmapDrawable) getResources().getDrawable(R.drawable.pig) ;
		Bitmap bitmap=bitmapDrawable.getBitmap();
		Rect src=new Rect(0,0,bitmap.getWidth(),bitmap.getHeight());
		Rect dst=new Rect(50,50,200,200);
		
		//旋转
		Matrix matrix=new Matrix();
		matrix.setRotate(90, getWidth()/2, getHeight()/2);
		canvas.setMatrix(matrix);
		
		canvas.drawBitmap(bitmap, src, dst, null);
		
		
		//draw cube
		canvas.setMatrix(null);
		paint.setColor(Color.rgb(255, 128, 128));
		canvas.drawRect(new Rect(cube.getX(), cube.getY(), cube.getX()
				+ cube.getSize(), cube.getY() + cube.getSize()), paint);
	}
}
